{% load static %}
<form id="js-cases-nav-form" action="{% url "testcases-all" %}" method="get">
	<input type="hidden" name="case_sort_by" value="{{ REQUEST_CONTENTS.case_sort_by }}" />
	<input type="hidden" name="plan" value="{{ REQUEST_CONTENTS.from_plan }}" />
	<input type="hidden" name="from_plan" value="{{ REQUEST_CONTENTS.from_plan }}" />
	<input type="hidden" name="template_type" value="{{ REQUEST_CONTENTS.template_type }}" />
	<div class="tab_navigation actions">
		<div class='toolbar'>
			<ul>
				<li>
					{% if perms.testcases.add_testcase %}
					<span id="js-case-menu" class='sprites toolbar_case icon_plan' data-params='["{% url "testcases-new" %}", {{ test_plan.plan_id }}]'>Case</span>
					{% else %}
					<span class='sprites toolbar_case icon_plan'>Case</span>
					{% endif %}
					<ul>
						{% if perms.testcases.add_testcase %}
						<li><input id="js-new-case" class="add_new icon_plan" type="button" value="Write new case" data-params='["{% url "testcases-new" %}", {{ test_plan.plan_id }}]'/></li>
						<li><input id="js-add-case-to-plan" type="button" class="search icon_plan" value="Add cases from other plans" data-param="{% url "plan-search-cases-for-link" test_plan.plan_id %}" /></li>
						{% else %}
						<li><input type="button" class="add_new icon_plan" disabled value="Write new case"/></li>
						<li><input type="button" class="search icon_plan" disabled value="Add cases from other plans" /></li>
						{% endif %}
						<li><input type="button" id="js-print-case" class="print_view icon_plan" value="Print"  title="print view of selected cases" data-param="{% url "testcases-printable" %}" /></li>
						{% if perms.testcases.add_testcase %}
						<li><input type="button" id="js-clone-case" class="clone icon_plan" value="Clone" title="Clone selected cases to another test plan" data-param="{% url "testcases-clone" %}" /></li>
						{% else %}
						<li><input type="button" class="clone icon_plan" value="Clone" title="Clone selected cases to another test plan" disabled /></li>
						{% endif %}
						{% if perms.testcases.delete_testcaseplan %}
						<li><input type="button" id="js-remove-case" class="delete icon_plan" value="Remove" title="Remove selected cases from this plan" /></li>
						{% else %}
						<li><input type="button" class="delete icon_plan" value="Remove" title="Remove selected cases from this plan" disabled /></li>
						{% endif %}
					</ul>
				</li>
                        {% if REQUEST_CONTENTS.template_type == 'case' and perms.testruns.add_testrun %}
                                <li>
                                    <span class='sprites toolbar_run{% if not perms.testruns.add_testrun %}_disabled{% endif %} icon_plan'>Run</span>
                                    <ul>
                                        <li><input type="button" class="new_run icon_plan" value="Create new TestRun" id="js-new-run" data-param="{% url "testruns-new" %}" /></li>
                                        <li><input type="button" class="search icon_plan" value="Add cases to run" id="js-add-case-to-run" data-param="{% url "plan-choose_run" test_plan.plan_id %}" /></li>
                                    </ul>
                                </li>
                        {% endif %}
			{% if perms.testcases.change_testcase %}
				<li><input type="button" value="Automated" title="change automated" class="btn_automated automated sprites icon_plan" /></li>
                                {% if REQUEST_CONTENTS.template_type == 'review_case' %}
                                <li><input type="button" value="Reviewer"       title="Change TestCase reviewer" class="btn_reviewer       assignee sprites icon_plan" /></li>
                                {% else %}
                                <li><input type="button" value="Default Tester" title="Change default tester"    class="btn_default_tester assignee sprites icon_plan" /></li>
                                {% endif %}
				<li><input type="button" value="Component" class="btn_component sprites component icon_plan" /></li>
				<li><span class='sprites toolbar_status icon_plan'>Status</span>
					<ul>
						{% for cs in case_status %}
						<li><input type='button' value='Set {{ cs }}' class='btn_case_status {{ cs|lower }} icon_plan js-status-item' data-param="{{ cs.pk }}" /></li>
						{% endfor %}
					</ul>
				</li>
				<li><input type="button" value="Category" class="btn_category sprites category icon_plan" /></li>
				<li><span class='sprites toolbar_priority icon_plan'>Priority</span>
					<ul>
						{% for priority in priorities %}
						<li><input type='button' value='Set {{ priority }}' class='btn_case_priority {{ priority|lower }} icon_plan js-priority-item' data-param="{{ priority.pk }}" /></li>
						{% endfor %}
					</ul>
				</li>
			{% endif %}
			</ul>
			<span class="reorder_case">
				<a class="btn_filter filtercase" title="Click to show filter options">Show filter options</a>
				{% if perms.testcases.change_testcase %}
				<a class="btn_sort sortlink" title="Click me,then Drag and drop the rows to adjust the order,and click 'Done Sorting' link to submit your changes">Re-order cases</a>
				{% endif %}
			</span>
		</div>
		<div class="mixbar fixed">
			<div class="tit" style="width: 50px; float: left; height: 100%; margin: 0px; text-align: center;">Tags:</div>
			<div style="margin-left: 50px; line-height:22px;" class="taglist">
				{% for tag in case_own_tags %}
				<a href="#testcases">{{ tag.name }}</a>&nbsp;&nbsp;<span class="grey">-</span>&nbsp;&nbsp;
				{% empty %}
				<span class="grey">No tags in cases</span>
				{% endfor %}
			</div>
		</div>
	</div>
	<div class="list_filter" {% ifnotequal REQUEST_CONTENTS.a 'search' %} style="display:none;" {% endifnotequal %}>
            <input type="hidden" name="a" value="search" />
            <input type="hidden" name="from_plan" value="{{ test_plan.pk }}" />
            <div class="leftlistinfo">
                <div class="listinfo">
                    <div class="title">Case&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.summary }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Author&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.author }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Tester&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.default_tester }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Priority&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.priority }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Automated&nbsp;:</div>
                    <div class="listinfo_input">
                        {{ search_form.is_automated }}
                        <div class="automatedlist">
                            {{ search_form.is_automated_proposed }}
                            <label>{{ search_form.is_automated_proposed.label }}</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="rightlistinfo">
                <div class="listinfo">
                    <div class="title">Category&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.category }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Status&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.case_status }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Component&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.component }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Tag&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.tag__name__in }}</div>
                </div>
                <div class="listinfo">
                    <div class="title">Items per page&nbsp;:</div>
                    <div class="listinfo_input">{{ search_form.items_per_page }}</div>
                </div>
            </div>
            <div class="setinput">{{ search_form.errors }}</div>
            <div class="clear"></div>

            <div class="submit-row bottom">
                <span class="tit"><span class="js-number-of-loaded-cases">{{ total_cases_count }}</span> Cases</span>
                <input type="submit" value="Filter cases" />
            </div>
	</div>
</form>
<div class="js-cases-select-all" display="display:none">
	<input type="checkbox" id="cases-select-all" name="cases-select-all" checked />
	<label for="cases-select-all">Also select all cases that are not yet shown below.</label>
</div>
<table class="list js-cases-list" cellpadding="1" cellspacing="0" border="0">
	<thead data-param="{{ test_plan.plan_id }}">
		<tr>
			<th class="nosort" align="left" width="18px">
				<a id='id_blind_all_link' class="blind_all_link">
					<img src="{% static 'images/t1.gif' %}" border="0" alt="" class="collapse-all" title="Expand all cases">
				</a>
			</th>
			<th class="nosort" align="left" width="20px">
				<input type="checkbox" value="all" checked />
			</th>
			<th align="left" class="widthID">
				<a title="Sort by case ID" href="#testcases" class="js-case-field" data-param="case_id">
					ID
				</a>
			</th>
			<th align="left">
				<a title="Sort by Summary" href="#testcases" class="js-case-field" data-param="summary">
					Test Case Summary
				</a>
			</th>
			<th align="left" width="90px">
				<a title="Sort by Author" href="#testcases" class="js-case-field" data-param="author">
					Author
				</a>
			</th>
			<th align="left" width="110px">
                            {% if REQUEST_CONTENTS.template_type == 'review_case' %}
                                <a title="Sort by Reviewer" href="#reviewcases" class="js-case-field" data-param="reviewer">
                                        Reviewer
                                </a>
                            {% else %}
				<a title="Sort by Default Tester" href="#testcases" class="js-case-field" data-param="default_tester">
					Default Tester
				</a>
                            {% endif %}
			</th>
			<th align="left" width="160px">
				<a title="Sort by automated" href="#testcases" class="js-case-field" data-param="is_automated">
					Automated
				</a>
			</th>
			<th align="left" width="130px">
				<a title="Sort by status" href="#testcases" class="js-case-field" data-param="case_status">
					Status
				</a>
			</th>
			<th align="left" width="100px">
				<a title="Sort by categoty" href="#testcases" class="js-case-field" data-param="category__name">
					Category
				</a>
			</th>
			<th align="left" width="60px">
				<a title="Sort by prority" href="#testcases" class="js-case-field" data-param="priority">
					Priority
				</a>
			</th>
			<th align="left" width="80px" style="display:none">Text version</th>
			<th align="left" width="40px">
				<a class="js-case-field" title="Sort by sortkey" href="#testcases" data-param="sortkey">
					Sort
				</a>
			</th>
			<th align="left" width="80px">Actions</th>
		</tr>
	</thead>
	<tbody>
		{% include 'plan/cases_rows.html' %}
	</tbody>
</table>
<div class="ajax_loading" style="display:none"></div>
<div class="cases-pagination show-more-cases">
	<a href="javascript:void(0)" class="load-more js-load-more" data-page-index="2" data-criterias="{{ search_criterias }}">Show more</a>
	<span class="js-loading-progress">
		(<span class="js-remaining-cases-count" data-cases-count="{{ total_cases_count|default:"0" }}">0</span> cases left)
	</span>
	<span class="js-nomore-msg" style="display:none">All cases have been loaded.</span>
</div>
